using Common;
using Grpc.Services;
using Infrastructure;
using Microsoft.EntityFrameworkCore;

namespace Grpc;

public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);
        
        builder.Services.AddDbContext<UserDbContext>(option =>
        {
            var connStr = builder.Configuration.GetConnectionString("uc_mysql");
            option.UseMySql(connStr, ServerVersion.AutoDetect(connStr));
        });
        builder.Services.AddInfrastructure();
        // Add services to the container.
        builder.Services.AddGrpc();
        builder.Services.AddControllers().AddJsonOptions(configure =>
        {
            configure.JsonSerializerOptions.Converters.Add(new JsonConverterDatetime());
            configure.JsonSerializerOptions.Converters.Add(new JsonConverterLong());
        });

        var app = builder.Build();
        
        app.MapGrpcService<GreeterService>();

        // Configure the HTTP request pipeline.
        app.MapGet("/",
            () =>
                "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");

        app.Run();
    }
}